package com.yocard.yxyd.ui.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.yocard.yxyd.utils.BigDecimalUtil;
import com.yocard.yxyd.utils.util.ActivityUtils;
import com.yocard.yxyd.utils.util.StringUtils;
import com.yocard.yxyd.utils.util.TimeUtils;
import com.gyf.barlibrary.ImmersionBar;
import com.yocard.yxyd.R;
import com.yocard.yxyd.base.AppContext;
import com.yocard.yxyd.http.model.response.CoinsBean;
import com.yocard.yxyd.ui.activity.base.SimpleActivity;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created on 2019/4/10.
 */
public class TransDetailActivity extends SimpleActivity {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_stream_no)
    TextView tvStreamNo;
    @BindView(R.id.tv_type)
    TextView tvType;
    @BindView(R.id.tv_count)
    TextView tvCount;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_balance)
    TextView tvBalance;
    @BindView(R.id.tv_note)
    TextView tvNote;

    @Override
    protected int getLayout() {
        return R.layout.act_trans_detail;
    }

    @Override
    protected void initEventAndData() {
        initTitle();
        initData();
    }

    private void initData() {
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            CoinsBean coinsBean = (CoinsBean) extras.getSerializable("data");
            tvStreamNo.setText(coinsBean.getStream_no());
            tvTime.setText(TimeUtils.millis2String(coinsBean.getCreated_at()*1000));
            tvBalance.setText(BigDecimalUtil.getFormatCoin(coinsBean.getRemain_coin()));
            if(StringUtils.isEmpty(coinsBean.getRemark())){
                tvNote.setText("无");
            }else {
                tvNote.setText(coinsBean.getRemark());
            }
            tvType.setText(coinsBean.getStreamable_type_chinese());
            String coinPrefix;
            if(("Order").equals(coinsBean.getStreamable_type_string())) {
                coinPrefix = "-";
                tvCount.setTextColor(AppContext.getColor_(R.color.color_ff001f));
            } else {
                coinPrefix = "+";
                tvCount.setTextColor(AppContext.getColor_(R.color.color_2bd321));
            }
            tvCount.setText(coinPrefix + BigDecimalUtil.getFormatCoin(coinsBean.getCoin()));
        }
    }

    private void initTitle() {
        ImmersionBar.with(this).statusBarColor(R.color.white)
                .statusBarDarkFont(true).navigationBarColor(R.color.white).init();
        tvTitle.setText("收支详情");
    }

    @OnClick({R.id.iv_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                ActivityUtils.finishActivity(this);
                break;
        }
    }
}
